<?php
//管理中心控制器类

class MangerAction extends Action{

    //管理中心首页
    public function index(){
		$this->assign('name',$_SESSION['user_name']);
                 $this->assign('kind',5);   //将菜单中显示的类别输出到模板
		$this->display('Manger:index');
                }
    function add_user(){
         $this->assign('kind',5);   //将菜单中显示的类别输出到模板
         $this->display('Manger:add_user');
    }
    function save_new_user(){   //Ajax保存添加的新用户

        //接收POST传送过来的数据
        $user_name=addslashes($_POST['user_name']);
        $user_pwd=$_POST['user_pwd'];
        $n_user_pwd=$_POST['n_user_pwd'];
        $admin=addslashes($_POST['admin']);

        if($user_name=='' or $user_pwd=='' or $n_user_pwd=='' or $admin==''){
            $this->ajaxReturn(0,'not null',0);
        }
        elseif($user_pwd!=$n_user_pwd){
            $this->ajaxReturn(1,'pwd two not',1);
        }
        else
        {
            $Manger=D('Manger');
            $user_pwd=md5($user_pwd);
            if($Manger->add_user($user_name,$user_pwd,$admin))
                 $this->ajaxReturn(2,'suessful',2);
            else
                $this->ajaxReturn(3,'change',3);
        }
    }
    function man_richeng(){   //日程管理
        $Richeng=D('Richeng');
        $list=$Richeng->get_all_richeng();
        $System=D('System');
        $list=$System->array_timetodate($list);
        $this->assign('list', $list);
        $this->assign('kind', 5);
        $this->display('Manger:man_richeng');
        
    }
    function user(){  //用户管理
        $this->assign('kind', 5);
        $this->display('Manger:user');
        
    }

    function save_gonggao(){
        $gg_title=addslashes($_POST['gg_title']);
        $gg_date=$_POST['gg_date'];
        $gg_body=addslashes($_POST['gg_body']);
        $Gonggao=D('Gonggao');
        $System=D('System');  //建立一个System模型
        if($gg_title=='' || $gg_date=='' || $gg_body==''){
            $this->ajaxReturn(0, 'not null', 0);   //检测是否为空，并Ajax返回0
        }
        elseif(!$System->isDate($gg_date)){
            $this->ajaxReturn(1, 'date error', 1);   //检测日期格式是否正确，并Ajax返回1
        }
        elseif($Gonggao->save_gonggao($gg_title,$System->get_time($gg_date),$gg_body)){
            $this->ajaxReturn(2, 'suessue', 2);   //添加成功，并Ajax返回2
        }
        
    }

}
?>